/**
 * 文件树中每个节点信息定义
 */
export class FileTreeEntry {
  public key: string
  public name: string
  public data?: any
  public children: FileTreeEntry[]
  get isFolder() {
    return this.children.length > 0
  }

  constructor(args: {
    name: string
    key?: string // 默认值同 name
    data?: any // 文件相关信息
    children?: FileTreeEntry[] // 默认空数组
  }) {
    const { key, name, children, data } = args

    this.name = name
    this.key = key || name
    this.data = data
    this.children = children || []
  }
  get isLeaf(): boolean {
    return this.children.length < 1
  }
}

export type FileTreeEntries = FileTreeEntry[]
